package spark.graphics.scenegraph;

import spark.math.Vector2;
import spark.math.Vector3;
import spark.math.Matrix;
import spark.graphics.Renderer;

public class TransformationNode extends SceneGraphNode {
	private Vector3 translation;
	private Matrix rotation;
	private Vector3 scale;

	public TransformationNode(Vector3 translation, Matrix rotation, Vector3 scale) {
		this.translation = translation;
		this.rotation = rotation;
		this.scale = scale;
	}

	@Override
	public void prepare() {
		Renderer.getInstance().getGl().glPushMatrix();
		if(translation != null) {
			Renderer.getInstance().getGl().glTranslatef(translation.x, translation.y, translation.z);
		}
		if(rotation != null) {
			Renderer.getInstance().getGl().glMultMatrixf(rotation.getMatrix(), 0);
		}
		if(scale != null) {
			Renderer.getInstance().getGl().glScalef(scale.x, scale.y, scale.z);
		}
	}

	@Override
	protected void cleanup() {
		Renderer.getInstance().getGl().glPopMatrix();
	}
}
